/*
 * @Author: shiyue 2647472992@qq.com
 * @Date: 2024-10-16 22:55:01
 * @LastEditors: shiyue 2647472992@qq.com
 * @LastEditTime: 2024-10-16 23:10:02
 * @FilePath: \protobuf\protobuf\fast_start\main.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%
 */
#include <iostream>
#include "practice1.pb.h"

int main()
{
    std::string people_str;
    {
        practice1::PeopleInfo people;
        people.set_name("张三");
        people.set_ages(18);
        if (!people.SerializeToString(&people_str))
        {
            std::cerr << "序列化联系人失败" << std::endl;
            return -1;
        }
        std::cout << "序列化成功, 结果: " << people_str << std::endl;
    }

    {
        practice1::PeopleInfo people;
        if(!people.ParseFromString(people_str))
        {
            std::cerr << "序列化联系人失败  " << std::endl;
            return -1;
        }

        std::cout << "反序列化成功  " << std::endl;
        std::cout << "姓名：" << people.name() << std::endl;
        std::cout << "年龄: " << people.ages()  << std::endl;

    }

    return 0;
}